package day_2022_9_to_12.Day;

/**
 * @author haomin
 * @date 2022/11/13 18:37
 **/
public class Day69_1_Num791_CustomSortString {
    class Solution {
        public String customSortString(String order, String s) {
            int[] cnts = new int[26];
            for (char c : s.toCharArray()) cnts[c - 'a']++;
            StringBuilder sb = new StringBuilder();
            for (char c : order.toCharArray()) {
                while (cnts[c - 'a']-- > 0) sb.append(c);
            }
            for (int i = 0; i < 26; i++) {
                while (cnts[i]-- > 0) sb.append((char)(i + 'a'));
            }
            return sb.toString();
        }
    }
}